<%@ include file="database_ini.jsp"%>
<%@page contentType="text/html; charset=UTF-8"%>
  <%@page import="org.json.*"%>
  <%
  	System.out.println("started:.....");
  	
  	String dropid = request.getParameter("dropid");
  	/*********debug*/
  	System.out.println(dropid);
  	/**********/
  	
  	String sql = "select CCKEY, Status from CCHDR where CCKEY = ?";
  	
  	pstmt = conn.prepareStatement(sql);
  	pstmt.setString(1 , dropid);
  	
  	ResultSet rs = pstmt.executeQuery();
  	
  	while(rs.next()){
  		
  		String CCKEY = rs.getString("CCKEY");
  		String Status = rs.getString("Status");
  		System.out.println(Status + "Status");
  		if (Status == null){
  	System.out.println("ok?");
  	//response.setStatus(404);
  	out.flush();
     			conn.close();
     			return;
  		}	
  	}
  	rs.close();
  	pstmt.close();
  	
  	System.out.println("ok?");
  	JSONObject obj=new JSONObject();
  	
  	/****************/
  	JSONArray jsonChildarray = new JSONArray();
  	
  	
  	//sql = "select CCKEY, Status from CCHDR where CCKEY = ?";
  	sql = "select LOC, SKU, DESCR, UPCCODE, LOTTBALOE05, CASECNT, sum(QTY) as QTY from CCDET WHERE CCKEY = '1' "
  	+ "group by LOC, SKU, DESCR, UPCCODE, LOTTBALOE05, CASECNT";
  	//pstmt.setString(1 , dropid);
  	pstmt = conn.prepareStatement(sql);
  	rs = pstmt.executeQuery();
  	while (rs.next()) {

  		String CCKEY = rs.getString("LOC");
  		String SKU = rs.getString("SKU");
  		String DESCR = rs.getString("DESCR");
  		String UPCCODE = rs.getString("UPCCODE");
  		String LOTTBALOE05 = rs.getString("LOTTBALOE05");
  		String CASECNT = rs.getString("CASECNT");
  		String QTY = rs.getString("QTY");

  		JSONObject child = new JSONObject();
  		child.put("CCKEY", CCKEY);
  		child.put("SKU", SKU);
  		child.put("DESCR", DESCR);
  		child.put("UPCCODE", UPCCODE);
  		child.put("LOTTBALOE05LOTTBALOE05", CCKEY);
  		child.put("CASECNT", CASECNT);
  		child.put("QTY", QTY);
  		jsonChildarray.put(child);

  	}

  	obj.put("jsonChildarray", jsonChildarray);
  	/****************/

  	/****************
  	obj.put("name","foo");
  	obj.put("num",new Integer(100));
  	obj.put("balance",new Double(1000.21));
  	obj.put("is_vip",new Boolean(true));
  	/****************/

  	out.print(obj);
  	System.out.println(obj);
  	out.flush();

  	conn.close();
  %>